package dao.impl;

import dao.ICatalogDAO;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import java.util.List;

public class CatalogDAO implements ICatalogDAO {
    private SessionFactory sessionFactory;

    public SessionFactory getSessionfactory() {
        return sessionFactory;
    }

    public void setSessionfactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public List getAllCatalogs() {
        Session session = sessionFactory.openSession();
        Transaction ts = session.beginTransaction();
        Query query = session.createQuery("from Catalog");
        List catalogs = query.list();
        ts.commit();
        session.close();
        return catalogs;
    }


}
